package com.ts.api.module.channel.service.impl;

import com.ts.api.module.channel.dao.ChannelHistoryUserDao;
import com.ts.api.module.channel.entity.po.ChannelUserRegisterPO;
import com.ts.api.module.channel.entity.qo.ChannelUserQO;
import com.ts.api.module.channel.service.ChannelHistoryUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ChannelHistoryUserServiceImpl implements ChannelHistoryUserService {

    @Autowired
    private ChannelHistoryUserDao channelHistoryUserDao;

    @Override
    @Transactional(readOnly = true)
    public ChannelUserRegisterPO get(ChannelUserQO channelUserQO) {
        return channelHistoryUserDao.get(channelUserQO);
    }

    @Override
    @Transactional(readOnly = true)
    public List<ChannelUserRegisterPO> listRightMatchPhone(ChannelUserQO channelUserQO) {
        return channelHistoryUserDao.listRightMatchPhone(channelUserQO);
    }

    @Override
    public ChannelUserRegisterPO insert(ChannelUserRegisterPO channelUserRegisterPO) {
        channelHistoryUserDao.insert(channelUserRegisterPO);
        return channelUserRegisterPO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int update(ChannelUserRegisterPO userRegisterPO) {
        return channelHistoryUserDao.update(userRegisterPO);
    }

    @Override
    @Transactional(readOnly = true)
    public int countByPhoneMd5(String phoneMd5) {
        return channelHistoryUserDao.countByPhoneMd5(phoneMd5);
    }

    @Override
    @Transactional(readOnly = true)
    public boolean hasLocalExist(String phoneMd5) {
        int row = channelHistoryUserDao.countByPhoneMd5(phoneMd5);
        return row > 0;
    }

    @Override
    @Transactional(readOnly = true)
    public Long getMaxId() {
        return channelHistoryUserDao.getMaxId();
    }
}
